﻿// For an introduction to the Page Control template, see the following documentation:
// http://go.microsoft.com/fwlink/?LinkId=232511
(function () {
    "use strict";

    WinJS.UI.Pages.define("/pages/addEvent/addEvent.html", {
        // This function is called whenever a user navigates to this page. It
        // populates the page elements with the app's data.
        init: function() {
            ViewModels.getUserFriends();
        },
        ready: function (element, options) {
            // TODO: Initialize the page here.
            var currentDate = {};
            var currentTime = {};

            var picker = document.getElementById("date-picker").winControl;
            picker.addEventListener("change", function (e) {
                currentDate = e.target.value;
            });

            var timePicker = document.getElementById("time-picker").winControl;
            timePicker.addEventListener("change", function (e) {
                currentTime = e.target.value;
            });

            WinJS.Utilities.id("create-event").listen("click", function () {
                var eventTime = currentDate;
                eventTime.setHours(currentTime.getHours());
                eventTime.setMinutes(currentTime.getMinutes());

                var data = {
                    title: document.getElementById("input-title").value,
                    notes: document.getElementById("input-desc").value,
                    place: document.getElementById("input-location").value,
                    time: eventTime
                }

                var persister = Persister.getPersister();
                persister.event.createEvent(data);
            });
        },

        unload: function () {
            // TODO: Respond to navigations away from this page.
        },

        updateLayout: function (element, viewState, lastViewState) {
            /// <param name="element" domElement="true" />

            // TODO: Respond to changes in viewState.
        }
    });
})();

//var computerTemplate = new WinJS.Binding.Template(null, {
//    href: "/templates/computer-template.html"
//});
